/*
 * @lc app=leetcode.cn id=112 lang=cpp
 *
 * [112] 路径总和
 */

// @lc code=start
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    void NodeSum(TreeNode *root,int Sum,vector<int> &TreeSum)
    {
        if(root == NULL)
            return;
        Sum+=root->val;
        if(root->left == NULL && root->right == NULL)
        {    
            TreeSum.push_back(Sum);
        }
        else
        {
            NodeSum(root->left,Sum,TreeSum);
            NodeSum(root->right,Sum,TreeSum);
        }
    }

    bool hasPathSum(TreeNode* root, int targetSum) {
        vector<int> TreeSum;
        int Sum = 0;
        NodeSum(root,Sum,TreeSum);
        for(auto it = TreeSum.begin();it!=TreeSum.end();it++)
        {
            if(*it == targetSum)
                return true;
        }
        return false;

    }
};
// @lc code=end

